<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->

<mat-expansion-panel class="log" expanded="true">
  <mat-expansion-panel-header class="log__header">
    <div class="log__header__title">Message</div>
    <span class="gio-badge-neutral">{{ messageLog?.timestamp | date: 'yyyy-MM-dd HH:mm:ss.SSS' }}</span>
  </mat-expansion-panel-header>

  <div class="log__data">
    <div class="log__row">
      <div class="log__row__cell">
        <div class="log__row__property">Request ID:</div>
        <div class="log__row__value">{{ messageLog.requestId }}</div>
      </div>
    </div>
    <div class="log__row">
      <div class="log__row__cell">
        <div class="log__row__property">Client ID:</div>
        <div class="log__row__value">{{ messageLog.clientIdentifier }}</div>
      </div>
    </div>
    <div class="log__row">
      <div class="log__row__cell">
        <div class="log__row__property">Correlation ID:</div>
        <div class="log__row__value">{{ messageLog.correlationId }}</div>
      </div>
    </div>
    <div class="log__row">
      <div class="log__row__cell" *ngIf="messageLog.parentCorrelationId">
        <div class="log__row__property">Parent Correlation ID:</div>
        <div class="log__row__value">{{ messageLog.parentCorrelationId }}</div>
      </div>
    </div>
    <div class="log__row">
      <div class="log__row__cell">
        <div class="log__row__property">Operation:</div>
        <div class="log__row__value" [ngClass]="messageLog.operation === 'SUBSCRIBE' ? 'gio-badge-accent' : 'gio-badge-warning'">
          {{ messageLog.operation | lowercase }}
        </div>
      </div>
    </div>

    <ng-container *ngIf="messageLog?.entrypoint as entrypoint">
      <div class="log__row">
        <div class="log__row__cell">
          <span class="gio-badge-primary">Entrypoint</span>
          <span class="gio-badge-primary">
            <mat-icon
              *ngIf="entrypointConnectorIcon"
              [svgIcon]="entrypointConnectorIcon"
              data-testid="entrypoint-connector-icon"
            ></mat-icon>
            {{ entrypoint.connectorId }}
          </span>
        </div>
      </div>
      <div class="log__row">
        <api-runtime-logs-message-item-content
          type="entrypoint"
          [content]="messageLog.entrypoint"
          [connectorIcon]="entrypointConnectorIcon"
        ></api-runtime-logs-message-item-content>
      </div>
    </ng-container>

    <ng-container *ngIf="messageLog?.endpoint as endpoint">
      <div class="log__row">
        <div class="log__row__cell">
          <span class="gio-badge-primary">Endpoint</span>
          <span class="gio-badge-primary">
            <mat-icon *ngIf="endpointConnectorIcon" [svgIcon]="endpointConnectorIcon" data-testid="endpoint-connector-icon"></mat-icon>
            {{ endpoint.connectorId }}
          </span>
        </div>
      </div>
      <div class="log__row">
        <api-runtime-logs-message-item-content
          type="endpoint"
          [content]="messageLog.endpoint"
          [connectorIcon]="endpointConnectorIcon"
        ></api-runtime-logs-message-item-content>
      </div>
    </ng-container>
  </div>
</mat-expansion-panel>
